package com.sun.designpatternsdemo.builder.bean

import android.util.Log

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/7/1 11:24
 * 描述：实体
 *抽象建造者
 */
abstract class Builder {
    abstract fun setPart(type:String,name:String)

    abstract fun getProduct():Product
}
class ConcreteBuilder: Builder() {
    private val product = Product()
    override fun setPart(type: String, name: String) {
        product.type = type
        product.name = name
    }

    override fun getProduct(): Product {
       return product
    }

}

//导演类
class Director{
    val builder = ConcreteBuilder()
    fun getAProduct():Product{
        builder.setPart(name = "奥迪汽车",type = "Q5")
        return builder.getProduct()
    }
    fun getBProduct():Product{
        builder.setPart(name = "宝马汽车",type = "X7")
        return builder.getProduct()
    }
}

data class Product(var name: String ="",var type: String=""){
    fun showProduct(){
        Log.e("---", "名称：$name")
        Log.e("---", "型号：$type")
    }
}